package com.yang.framework.disruptor;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 支付通知消息的生产者第二种写法
 *
 * @author 杨 强
 * @package com.yang.framework.disruptor
 * @createTime 2023-09-10 15:03
 */
@Component
public class PayNoticeEventProducerWithTranslator {

    @Resource
    private RingBuffer<PayNoticeEvent> payNoticeRingBuffer;

    // 一个translator可以看做一个事件初始化器，publicEvent方法会调用它, 填充Event
    private static final EventTranslatorOneArg<PayNoticeEvent, PayNoticeEvent> TRANSLATOR =
            (event, sequence, data) -> BeanUtils.copyProperties(data, event);


    public void onData(PayNoticeEvent bb) {
        payNoticeRingBuffer.publishEvent(TRANSLATOR, bb);
    } 
} 